package com.guoxin.thread.concurrent.chapter6;

public class ThreadCloseGraceful2 {

    private static class Worker extends Thread {

        @Override
        public void run() {
            while (true) {
               /* try {
                    Thread.sleep(10_000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    System.out.println("Thread is shutdown");
                    return;
                }*/
               if(this.isInterrupted()){
                   System.out.println("Thread is shutdown");
                   return;
               }
            }
        }
    }


    public static void main(String[] args) {
        Worker worker = new Worker();
        worker.start();

        try {
            Thread.sleep(5_000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        worker.interrupt();
    }
}
